package day02;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class test3 {
    public static void main(String[] args) throws InterruptedException {
        Room room = new Room();
        Thread t1 = new Thread("t1") {
            @Override
            public void run() {
                room.increament();
            }
        };

        Thread t2 = new Thread("t2") {
            @Override
            public void run() {
                room.decreament();
            }
        };

        t1.start();
        t2.start();

        t1.join();
        t2.join();
        log.debug(String.valueOf(room.getCount()));

    }

}


class Room{
    private int count = 0;

    public void increament(){
        synchronized (this){
            for (int i = 0; i < 5000; i++) {
                count++;
            }

        }

    }


    public void decreament(){
        synchronized (this){
            for (int i = 0; i < 5000; i++) {
                count--;
            }
        }
    }

    public int getCount(){
        return count;
    }
}